home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / CBGRX103.ZIP / contrib / libgrx / src / lineclip.h < prev    next >
Text File  |  1993-12-06  |  3KB  |  98 lines

  1. /** 
  2.  ** LINECLIP.H 
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #ifndef _CLIPPING_H_
  25.  
  26. #include "scale.h"
  27. #include "clipping.h"
  28.  
  29. #define CLIPLINE(c,x1,y1,x2,y2) do {                    \
  30.     register int temp;                            \
  31.                                     \
  32.     if(x1 > x2)                                \
  33.     { EXCHG(x1,x2); EXCHG(y1,y2); }                    \
  34.     if((x2 < c->gc_xcliplo) || (x1 > c->gc_xcliphi))            \
  35.     { WHEN_OUTSIDE; }                        \
  36.     if(y1 < y2) {                            \
  37.     if((y2 < c->gc_ycliplo) || (y1 > c->gc_ycliphi)) {        \
  38.         WHEN_OUTSIDE;                        \
  39.     }                                \
  40.     if(y1 < c->gc_ycliplo) {                    \
  41.         USCALE(temp,(x2 - x1),(c->gc_ycliplo - y1),(y2 - y1));    \
  42.         if((x1 += temp) > c->gc_xcliphi) { WHEN_OUTSIDE; }        \
  43.         y1 = c->gc_ycliplo;                        \
  44.         WHEN_CLIPPED;                        \
  45.     }                                \
  46.     if(y2 > c->gc_ycliphi) {                    \
  47.         USCALE(temp,(x2 - x1),(y2 - c->gc_ycliphi),(y2 - y1));    \
  48.         if((x2 -= temp) < c->gc_xcliplo) { WHEN_OUTSIDE; }        \
  49.         y2 = c->gc_ycliphi;                        \
  50.         WHEN_CLIPPED;                        \
  51.     }                                \
  52.     if(x1 < c->gc_xcliplo) {                    \
  53.         USCALE(temp,(y2 - y1),(c->gc_xcliplo - x1),(x2 - x1));    \
  54.         y1 += temp;                            \
  55.         x1 = c->gc_xcliplo;                        \
  56.         WHEN_CLIPPED;                        \
  57.     }                                \
  58.     if(x2 > c->gc_xcliphi) {                    \
  59.         USCALE(temp,(y2 - y1),(x2 - c->gc_xcliphi),(x2 - x1));    \
  60.         y2 -= temp;                            \
  61.         x2 = c->gc_xcliphi;                        \
  62.         WHEN_CLIPPED;                        \
  63.     }                                \
  64.     }                                    \
  65.     else {                                \
  66.     if((y1 < c->gc_ycliplo) || (y2 > c->gc_ycliphi)) {        \
  67.         WHEN_OUTSIDE;                        \
  68.     }                                \
  69.     if(y1 > c->gc_ycliphi) {                    \
  70.         USCALE(temp,(x2 - x1),(y1 - c->gc_ycliphi),(y1 - y2));    \
  71.         if((x1 += temp) > c->gc_xcliphi) { WHEN_OUTSIDE; }        \
  72.         y1 = c->gc_ycliphi;                        \
  73.         WHEN_CLIPPED;                        \
  74.     }                                \
  75.     if(y2 < c->gc_ycliplo) {                    \
  76.         USCALE(temp,(x2 - x1),(c->gc_ycliplo - y2),(y1 - y2));    \
  77.         if((x2 -= temp) < c->gc_xcliplo) { WHEN_OUTSIDE; }        \
  78.         y2 = c->gc_ycliplo;                        \
  79.         WHEN_CLIPPED;                        \
  80.     }                                \
  81.     if(x1 < c->gc_xcliplo) {                    \
  82.         USCALE(temp,(y1 - y2),(c->gc_xcliplo - x1),(x2 - x1));    \
  83.         y1 -= temp;                            \
  84.         x1 = c->gc_xcliplo;                        \
  85.         WHEN_CLIPPED;                        \
  86.     }                                \
  87.     if(x2 > c->gc_xcliphi) {                    \
  88.         USCALE(temp,(y1 - y2),(x2 - c->gc_xcliphi),(x2 - x1));    \
  89.         y2 += temp;                            \
  90.         x2 = c->gc_xcliphi;                        \
  91.         WHEN_CLIPPED;                        \
  92.     }                                \
  93.     }                                    \
  94. } while(0)
  95.  
  96. #endif /* whole file */
  97.  
  98.